package Test;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import tools.getProcess;

/**
* Filename:    testMain.java
* @author:     yyi
* @version:    1.0
* @date:   2018-12-3
* @Description:
 */

public class testMain {
    public static String subString(String str, String strStart, String strEnd) {
        int strStartIndex = str.indexOf(strStart);
        int strEndIndex = str.indexOf(strEnd);
        if (strStartIndex < 0) {
            return "字符串 :---->" + str + "<---- 中不存在 " + strStart + ", 无法截取目标字符串";
        }
        if (strEndIndex < 0) {
            return "字符串 :---->" + str + "<---- 中不存在 " + strEnd + ", 无法截取目标字符串";
        }
        String result = str.substring(strStartIndex, strEndIndex).substring(strStart.length());
        return result;
    }

    private String getPID() {
        String pid = null;
        String cmd = "tasklist /nh /FI \"IMAGENAME eq DASS.exe\"";
        try {
            Runtime runtime = Runtime.getRuntime();
            Process process = runtime.exec(cmd);
            BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream()));
            String line = null;
            while((line=br.readLine()) != null){
                if(line.indexOf("DASS.exe") != -1){
                    String lineWithOutSpace = line.replace(" ","");
                    pid = subString(lineWithOutSpace,"DASS.exe","Console");
                    return pid;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
        return pid;
    }

}
